package com.yxjx.duoxue.datamodel;

import java.io.Serializable;

import org.json.JSONException;
import org.json.JSONObject;

import com.yxjx.duoxue.utils.UIHelper;

public class DMProduct implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5864733461201288955L;
	
	private Long id;
	private Integer productType;
	private Long productTypeId;
	private String productName;
	private String productDes;
	private Integer costPrice;
	private Integer discountPrice;
	private Integer unitUserCount;
	private Integer totalCount;
	private Long productBeginTime;
	private Long productEndTime;
	private Integer productStatus;
	
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public int getProductType() {
		return productType;
	}
	public void setProductType(int productType) {
		this.productType = productType;
	}
	public long getProductTypeId() {
		return productTypeId;
	}
	public void setProductTypeId(long productTypeId) {
		this.productTypeId = productTypeId;
	}
	public String getProductName() {
		return productName;
	}
	public void setProductName(String productName) {
		this.productName = productName;
	}
	public int getProductStatus() {
		return productStatus;
	}
	public void setProductStatus(int productStatus) {
		this.productStatus = productStatus;
	}
	public long getProductEndTime() {
		return productEndTime;
	}
	public void setProductEndTime(long productEndTime) {
		this.productEndTime = productEndTime;
	}
	public long getProductBeginTime() {
		return productBeginTime;
	}
	public void setProductBeginTime(long productBeginTime) {
		this.productBeginTime = productBeginTime;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	public int getCostPrice() {
		return costPrice;
	}
	public void setCostPrice(int costPrice) {
		this.costPrice = costPrice;
	}
	public String getProductDes() {
		return productDes;
	}
	public void setProductDes(String productDes) {
		this.productDes = productDes;
	}
	public int getDiscountPrice() {
		return discountPrice;
	}
	public void setDiscountPrice(int discountPrice) {
		this.discountPrice = discountPrice;
	}
	public int getUnitUserCount() {
		return unitUserCount;
	}
	public void setUnitUserCount(int unitUserCount) {
		this.unitUserCount = unitUserCount;
	}
	
	public static DMProduct from(String str) {
		if (UIHelper.isEmpty(str)) {
			return null;
		}
		DMProduct product = null;
		try {
			JSONObject jo = new JSONObject(str);
			product = new DMProduct();
			product.setId(jo.getLong("id"));
			product.setProductType(jo.getInt("productType"));
			product.setProductTypeId(jo.getLong("productTypeId"));
			product.setProductName(jo.getString("productName"));
			product.setProductDes(jo.getString("productDes"));
			product.setCostPrice(jo.getInt("costPrice"));
			product.setDiscountPrice(jo.getInt("discountPrice"));
			product.setUnitUserCount(jo.getInt("unitUserCount"));
			product.setTotalCount(jo.getInt("totalCount"));
			product.setProductBeginTime(jo.getLong("productBeginTime"));
			product.setProductEndTime(jo.getLong("productEndTime"));
			product.setProductStatus(jo.getInt("productStatus"));
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return product;
	}
	
	@Override
	public String toString() {
		return  "(" +
				"id" + " " + id + "," +
				"productType" + " " + productType + "," +
				"productTypeId" + " " + productTypeId + "," + 
				"productName" + " " + productName + "," +
				"productDes" + " " + productDes + "," +
				"costPrice" + " " + costPrice + "," +
				"discountPrice" + " " + discountPrice + "," +
				"unitUserCount" + " " + unitUserCount + "," +
				"totalCount" + " " + totalCount + "," +
				"productBeginTime" + " " + productBeginTime + "," +
				"productEndTime" + " " + productEndTime + "," +
				"productStatus" + " " + productStatus + ")"
				;
	}

}
